<?php

namespace App\Home\Controllers;

use App\Home\Filters\WorshipArtistFilter;
use App\Home\Models\WorshipArtist;
use App\Home\Requests\WorshipArtistRequest;
use App\Home\Resources\WorshipArtistResource;
use Illuminate\Http\Request;

class WorshipArtistController extends Controller
{
    public function store(
        WorshipArtistRequest $request, 
        WorshipArtist $worshipArtist
    ){
        $inputs = $request->validated();
        $worshipArtist = $worshipArtist->add($inputs);

        return $this->created(WorshipArtistResource::make($worshipArtist));
    }

    public function update(
        WorshipArtistRequest $request, 
        WorshipArtist $worshipArtist
    ){
        $inputs = $request->validated();
        $worshipArtist->update($inputs);

        return $this->created(WorshipArtistResource::make($worshipArtist));
    }

    public function destroy(
        WorshipArtist $worshipArtist
    ){
        $worshipArtist->delete();
        return $this->noContent();
    }

    public function index(
        WorshipArtistRequest $request,
        WorshipArtistFilter $filter
    ){
        $fields = [
            "*",
        ];
        $worshipArtists = WorshipArtist::query()
            ->filter($filter)
            ->select($fields)
            ->paginate();

        return $this->ok(WorshipArtistResource::collection($worshipArtists));
    }

    public function show(
        Int $id
    ){
        $fields = [
            "*",
        ];
        $worshipArtist = WorshipArtist::query()
            ->select($fields)
            ->find($id);
        return $this->ok(WorshipArtistResource::make($worshipArtist));
    }
}
